package com.haizhi.crm.api.controller.search;

import com.haizhi.crm.api.constant.MediaType;
import com.haizhi.crm.common.model.Response;
import com.haizhi.crm.search.model.SearchQo;
import com.haizhi.crm.search.model.SearchVo;
import com.haizhi.crm.search.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chengmo on 2018/5/15.
 */
@Api(description = "[搜索]通用接口" )
@RestController
@RequestMapping("/search" )
public class SearchController {

    @Autowired
    private SearchService searchService;

    @ApiOperation(value = "通用搜索接口", notes = "模糊搜索 {\"graph\": \"crm_dev2\",\"keyword\": \"海致\"}" )
    @PostMapping(path = "", consumes = MediaType.APP_JSON, produces = MediaType.APP_JSON)
    public Response search(@RequestBody SearchQo searchQo) {
        SearchVo vo = searchService.search(searchQo);
        return Response.success(vo);
    }

    @ApiOperation(value = "搜索词推荐", notes = "输入 {\"graph\": \"crm_dev2\",\"pageSize\": 5,\"keyword\": \"海致\"}" )
    @PostMapping(path = "/suggest", consumes = MediaType.APP_JSON, produces = MediaType.APP_JSON)
    public Response suggest(@RequestBody SearchQo searchQo) {
        SearchVo vo = searchService.suggest(searchQo);
        return Response.success(vo);
    }

}
